package www.wen.com.common.lib.util

import android.content.Context
import android.content.pm.PackageManager
import www.wen.com.common.lib.app.BaseApplication

/**
 * @author WEN
 * @Description:
 * @date 2020/12/9 16:32
 */
object LocalInfoUtil {

    @JvmStatic
    fun getLocalVersionName(ctx: Context = BaseApplication.CONTEXT): String {
        var localVersion = ""
        try {
            val packageInfo = ctx.applicationContext.packageManager.getPackageInfo(ctx.packageName, 0)
            localVersion = packageInfo.versionName
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
        }
        return localVersion
    }


    fun getLocalVersionCode(ctx: Context = BaseApplication.CONTEXT): Int {
        var localVersionCode = -1
        try {
            val packageInfo = ctx.applicationContext.packageManager.getPackageInfo(ctx.packageName, 0)
            localVersionCode = packageInfo.versionCode
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
        }
        return localVersionCode
    }

}